﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace DB
{
    public class GeneralParameter
    {
        public string ID;
        public string Value;
    }
    public class GeneralParameterDb : DbBase
    {
        private GeneralParameterDb(DbEngineBase dbEngineBase)
            : base(dbEngineBase)
        {
        }

        private static GeneralParameterDb _dbMysql;
        public static GeneralParameterDb DbMysql
        {
            get 
            {
                return _dbMysql ?? (_dbMysql = new GeneralParameterDb(new DbEngineMysql("Server=mail.maibey.com;userid=love;password=1234567;Database=Barn;CharSet=utf8;")));
            }
        }

        public GeneralParameter GetGeneralParameter(string ID)
        {
            var strErr = "";
            var dt = this.QueryData("Select * from GeneralParameter where id = '"+ID+"'", ref strErr);
            if (dt.Rows.Count <= 0) return null;
            return Get(dt.Rows[0]);
        }
        public bool Update(GeneralParameter generalParameter)
        {
            var strErr = "";
            return this.Exec("Update GeneralParameter set Value = '" + generalParameter.Value + "' where id = '" + generalParameter.ID + "'", ref strErr);
        }
        public bool Insert(GeneralParameter generalParameter)
        {
            var strErr = "";
            return this.Exec("insert GeneralParameter (Value,id) VALUES ('" + generalParameter.Value + "' , '" + generalParameter.ID + "')", ref strErr);
        }

        private GeneralParameter Get(DataRow row)
        {
            var generalParameter = new GeneralParameter {ID = row["ID"].ToString(), Value = row["Value"].ToString()};
            return generalParameter;
        }
    }
}
